package com.codebo.homiematchbackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.codebo.homiematchbackend.common.ErrorCode;
import com.codebo.homiematchbackend.constant.UserConstant;
import com.codebo.homiematchbackend.exception.ThrowUtils;
import com.codebo.homiematchbackend.model.entity.Follow;
import com.codebo.homiematchbackend.model.entity.User;
import com.codebo.homiematchbackend.service.FollowService;
import com.codebo.homiematchbackend.mapper.FollowMapper;
import com.codebo.homiematchbackend.service.UserService;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

/**
* @author 25912
* @description 针对表【follow(关注表)】的数据库操作Service实现
* @createDate 2025-09-23 17:16:23
*/
@Service
public class FollowServiceImpl extends ServiceImpl<FollowMapper, Follow>
    implements FollowService{


    @Override
    public Boolean isFollow(long id, HttpServletRequest httpServletRequest)
    {
        Object object = httpServletRequest.getSession().getAttribute(UserConstant.USER_LOGIN_STATE);
        ThrowUtils.throwIf(object == null, ErrorCode.NOT_LOGIN_ERROR);
        User user = (User) object;
        QueryWrapper< Follow> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", user.getId())
                .eq("followed_id", id);
        Follow follow = this.getOne(queryWrapper);
        return follow != null;
    }
}




